package com.zx.cloud.common.rw;

import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

public class DataSourceAspect {

	public void before(JoinPoint point) {
		String datasource =ProjectDataSource.TIGER_ADMIN.getCode();
		try {
			Method m = ((MethodSignature) point.getSignature()).getMethod();
			if (m != null && m.isAnnotationPresent(DataSource.class)) {
				DataSource data = m.getAnnotation(DataSource.class);
				datasource = data.value().getCode();
//			}else{
//				String methodName=m.getName();
//				if(!StringUtils.isEmpty(methodName)){
//					if((methodName).startsWith("query")||(methodName).startsWith("get")||(methodName).startsWith("find")||(methodName).startsWith("select")||(methodName).startsWith("list")||(methodName).startsWith("page")){
//						datasource = "master_" + "read";
//					}
//				}
			}
//			System.err.println("-2-DataSourceAspect.before----datasource["+datasource+"]");
			HandleDataSource.putDataSource(datasource);
		} catch (Exception e) {
			HandleDataSource.putDataSource(datasource);
			e.printStackTrace();
		}
	}
}
